<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>图书信息添加页面</title>
<link rel="stylesheet" href="../layui/css/layui.css" media="all">
<style>
.layui-btn:not(.layui-btn-lg ):not(.layui-btn-sm):not(.layui-btn-xs) {
	height: 34px;
	line-height: 34px;
	padding: 0 8px;
}
</style>
</head>
<body>
	<form class="layui-form" action="">
	<div class="layui-form-item" style="margin-top: 20px;" onsubmit="false">
		<div class="layui-form-item">
			<label class="layui-form-label">图书名称:</label>
			<div class="layui-input-inline" style="width: 350px;">
				<input type="text" id="b_name" name="b_name" required=""
			 lay-reqtext="图书名称不能为空" placeholder="请输入图书名称"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图书出版社:</label>
			<div class="layui-input-inline" style="width: 350px;">
				<input type="text" id="b_publisher" name="b_publisher" required=""
				 lay-reqtext="图书出版社不能为空" placeholder="请输入图书的出版社"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图书作者:</label>
			<div class="layui-input-inline" style="width: 350px;">
				<input type="text" id="b_author" name="b_author" required=""
				lay-reqtext="图书作者不能为空" placeholder="请输入图书作者"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图书库存:</label>
			<div class="layui-input-inline" style="width: 350px;">
				<input type="text" id="b_stock" name="b_stock" required=""
				lay-reqtext="图书库存不能为空" placeholder="请输入图书库存"
					autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">所属阅览室:</label>
			<div class="layui-input-inline" style="width: 120;">
				<select name="b_readrooms_id" id="b_readrooms_id"
					class="layui-input" lay-verify="required">
					<option value="">请选择所属阅览室</option>
					<option value="1">1号图书房</option>
					<option value="2">2号图书房</option>
				</select>
			</div>
		</div>
		<div class="layui-btn-container" style="text-align: center;">
			<button class="layui-btn" lay-filter="booksBtu" lay-submit="">
				添加</button>
		</div>
		</div>
	</form>
	<script type="text/javascript" src="../layui/layui.js"></script>
	<script>
		//加载了layui的form模块
		layui.use([ 'form' ], function() {
			var form = layui.form;
			var $ = layui.jquery; //引入jquery
			//监听提交
			form.on('submit(booksBtu)', function(data) {
				var d = data.field; //表单中的数据，定义一个对象来接收
				d.method = "add";
				//通过ajax向数据库提交数据了
				console.log(d); //提交之前的一个数据验证、通过打印的方式先手动的去判断一下这个数据
				var url = '../addBooks';
				$.post(url, d, function(data) {
					if (data.count > 0) {
						console.log('添加成功');
						var index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
						parent.layer.close(index); //关闭窗口
					}
				}, "json");
				return false;
			});
		});
	</script>
</body>
</html>